import java.util.*;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2022-11-25
 * Time: 9:30
 */
class NumArray {
    public int[] arr;

    public NumArray(int[] nums) {
        arr = new int[nums.length+1];
        // 前缀和从 1 开始
        for (int i = 1; i <= nums.length; i++) {
            arr[i] = nums[i-1] + arr[i-1];
        }
    }

    public int sumRange(int l, int r) {
        l++;
        r++;
        return arr[r] - arr[l-1];
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        int sum = arr[0];
        for (int i = 1; i < n; i++) {
            arr[i] += Math.max(arr[i-1], 0);
            sum = Math.max(sum, arr[i]);
        }
        System.out.println(sum);
    }

    public static boolean isPalindromic(String str) {
        int i = 0;
        int j = str.length()-1;
        while (i <= j) {
            if (str.charAt(i) != str.charAt(j)) {
                return false;
            }
            i++;
            j--;
        }
        return true;
    }
    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        String s1 = in.nextLine();
        String s2 = in.nextLine();
        List<Character> list2 = new ArrayList<>();
        for (int i = 0; i < s2.length(); i++) {
            list2.add(s2.charAt(i));
        }
        int count = 0;
        for (int i = 0; i < s1.length()+1; i++) {
            List<Character> list1 = new ArrayList<>();
            for (int j = 0; j < s1.length(); j++) {
                list1.add(s1.charAt(j));
            }
            list1.addAll(i, list2);
            StringBuilder stringBuilder = new StringBuilder();
            for (char ch : list1) {
                 stringBuilder.append(ch);
            }
            if (isPalindromic(stringBuilder.toString())) {
                count++;
            }
        }
        System.out.println(count);
    }
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();
        boolean flg = false;
        StringBuilder stringBuilder = new StringBuilder();
        String s = "0123456789ABCDEF";
        if (m < 0) {
            m = -m;
            flg = true;
        }
        if (m == 0) {
            stringBuilder.append(0);
        }
        while (m != 0) {
            stringBuilder.append(s.charAt(m%n));
            m /= n;
        }
        if (flg) {
            stringBuilder.append("-");
        }
        System.out.println(stringBuilder.reverse());
    }


    // 计算糖果
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = 0;
        int b = 0;
        int c = 0;
        int ret1 = in.nextInt();
        int ret2 = in.nextInt();
        int ret3 = in.nextInt();
        int ret4 = in.nextInt();
        boolean flag = false;
        for (a = 0; a <= 30; a++) {
            for (b = 0; b <= 30; b++) {
                for (c = 0; c <= 30; c++) {
                    if (a-b == ret1 && b-c == ret2 && a+b == ret3 && b+c == ret4) {
                        System.out.print(a+" ");
                        System.out.print(b+" ");
                        System.out.print(c+" ");
                        flag = true;
                    }
                }
            }
        }
        if (!flag) {
            System.out.println("No");
        }
    }
}
